package com.online.study.system.service.impl;

import com.online.study.system.entity.Dictionary;
import com.online.study.system.model.dto.DictionaryDto;
import com.online.study.system.repository.DictionaryRepository;
import com.online.study.system.service.DictionaryService;
import com.online.study.system.service.mapstruct.DictionaryMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Resource
    private DictionaryRepository dictionaryRepository;

    @Resource
    private DictionaryMapper dictionaryMapper;

    @Override
    public List<DictionaryDto> getAllDictionary() {
        List<Dictionary> all = dictionaryRepository.findAll();
        return all.stream()
                .map(entity -> dictionaryMapper.toDto(entity))
                .collect(Collectors.toList());
    }
}
